@extends('backend.layouts.app')
@section('content')
<div class="layui-card">
    <div class="layui-card-header layui-card-header-auto">
        权重设置
    </div>
    <div class="layui-card-body">
        <div class="layui-row" style="margin-bottom:10px">
            <div class="layui-col-md9">
                &nbsp;&nbsp;
            </div>
            <div class="layui-col-md3">
                <div class="layui-btn-group" style="float:right">
                    <a href="{{route('admin.resume.evaluation.config.create')}}" class="layui-btn layui-btn-sm">添加</a>
                </div>
            </div>
        </div>
        <table id="dataTable" lay-filter="dataTable">
            <script type="text/html" id="sort_options">
                <div class="layui-btn-group">
                    <a class="layui-btn layui-btn-sm" lay-event="up">上升</a>
                    <a class="layui-btn layui-btn-sm layui-btn-danger" lay-event="down">下降</a>
                </div>
            </script>
            <script type="text/html" id="options">
                <div class="layui-btn-group">
                    <a class="layui-btn layui-btn-sm" lay-event="show">查看</a>
                    <a class="layui-btn layui-btn-sm" lay-event="edit">编辑</a>
                    <a class="layui-btn layui-btn-sm" lay-event="content">详细信息</a>
                    <a class="layui-btn layui-btn-sm layui-btn-danger" lay-event="del">删除</a>
                </div>
            </script>
        </table>
    </div>
</div>
@endsection

@section('script')
<script type="text/javascript">
    layui.use(['layer', 'form', 'index', 'table'], function () {
        let layer = layui.layer;
        let form = layui.form;
        let table = layui.table;

        dataTable = table.render({
            elem: '#dataTable',
            url: "{{route('admin.resume.evaluation.config.pageList')}}",
            page: true,
            cols: [
                [{
                    title: '名称',
                    field: 'name',
                    width: 200
                }, {
                    title: '默认',
                    templet: function (res) {
                        let defaults = res.is_default;
                        let default_html;
                        if (defaults == 1 || defaults == '1') {
                            default_html = '<a class="layui-btn layui-btn-sm" lay-event="defaults">是</a>';
                        }else{
                            default_html = '<a class="layui-btn layui-btn-sm layui-btn-danger" lay-event="defaults">否</a>';
                        } 
                        return default_html;
                    }
                }, {
                    title: '备注',
                    field: 'description'
                }, {
                    title: '有效',
                    align: 'center',
                    templet: function (res) {
                        let status = res.status;
                        let status_html;
                        if (status == 1 || status == '1') {
                            status_html =
                                '<a class="layui-btn layui-btn-sm" lay-event="status">有效</a>'
                        } else {
                            status_html =
                                '<a class="layui-btn layui-btn-sm layui-btn-danger" lay-event="status">无效</a>'
                        }
                        return status_html;
                    }
                }, {
                    title: '排序',
                    align: 'center',
                    toolbar: '#sort_options'
                }, {
                    title: '操作',
                    fixed: 'right',
                    align: 'center',
                    toolbar: '#options'
                }]
            ]
        });

        table.on('tool(dataTable)', function (obj) {
            let data = obj.data;
            let layEvent = obj.event;

            switch (layEvent) {
                case 'show':
                    location.href = 'config/' + data.config_id + '/show';
                    break;
                case 'edit':
                    location.href = 'config/' + data.config_id + '/edit';
                    break;
                case 'content':
                    location.href = 'config/contents?config_id=' + data.config_id;
                    break;
                case 'del':
                    layer.confirm('确认删除吗？', function (index) {
                        $.post("{{ route('admin.resume.evaluation.config.destroy') }}", {
                                '_method': 'delete',
                                '_token': '{{csrf_token()}}',
                                ids: data.config_id
                            },
                            function (result) {
                                layer.msg(result.msg);
                                dataTable.reload();
                            });
                    });
                    break;
                case 'up':
                    $.post("{{ route('admin.resume.evaluation.config.decrement')}}", {
                        '_method': 'put',
                        '_token': '{{csrf_token()}}',
                        id: data.config_id
                    }, function (result) {
                        layer.msg(result.msg);
                        dataTable.reload();
                    });
                    break;
                case 'down':
                    $.post("{{ route('admin.resume.evaluation.config.increment')}}", {
                        '_method': 'put',
                        '_token': '{{csrf_token()}}',
                        id: data.config_id
                    }, function (result) {
                        layer.msg(result.msg);
                        dataTable.reload();
                    });
                    break;
                case 'status':
                    $.post("{{ route('admin.resume.evaluation.config.status')}}", {
                        '_method': 'put',
                        '_token': '{{csrf_token()}}',
                        id: data.config_id
                    }, function (result) {
                        layer.msg(result.msg);
                        dataTable.reload();
                    });
                    break;
                case 'defaults':
                    $.post("{{ route('admin.resume.evaluation.config.defaults')}}", {
                        '_method': 'put',
                        '_token': '{{csrf_token()}}',
                        id: data.config_id
                    }, function (result) {
                        layer.msg(result.msg);
                        dataTable.reload();
                    });
                    break;
                default:
                    break;
            }
        });
    });

</script>
@endsection